<?php
session_start(); 
$caption=$_POST['caption'];
//$albumid='6';
$cuiid = $_SESSION['username'];
$albumid=$_POST['message'];

//echo 'Message'.$caption.$cuiid.$albumid;

$conn = oci_connect("gaurav", "gaurav", "xe"); 
$lob = oci_new_descriptor($conn, OCI_D_LOB);
$stmt = oci_parse($conn, 'INSERT INTO PHOTOS (PHOTOID, IMAGE, CAPTION, ALBUMID, CreationDate) VALUES(photosseq.nextval, EMPTY_BLOB(), :caption, :albumid, SysDate) RETURNING IMAGE INTO :IMAGE');
//$stmt = oci_parse($conn, 'UPDATE CANDIDATE SET SELFIMAGE = EMPTY_BLOB() WHERE CUID = :cuiid RETURNING SELFIMAGE INTO :SELFIMAGE');
          //oci_bind_by_name($stmt, ':CAPTION', $caption);
		  //oci_bind_by_name($stmt, ':ALBUMID', $albumid);
		  oci_bind_by_name($stmt, ':IMAGE', $lob, -1, OCI_B_BLOB);
		  oci_bind_by_name($stmt, ':CUIID', $cuiid);
		  oci_bind_by_name($stmt, ':CAPTION', $caption);
  		  oci_bind_by_name($stmt, ':ALBUMID', $albumid);
          oci_execute($stmt, OCI_DEFAULT);

          // The function $lob->savefile(...) reads from the uploaded file.
          // If the data was already in a PHP variable $myv, the
          // $lob->save($myv) function could be used instead.
          if ($lob->savefile($_FILES['empphoto']['tmp_name'])) 
		  {
            oci_commit($conn);
          }
          else {
            echo "Couldn't upload Blob\n";
          }
          $lob->free();
          oci_free_statement($stmt);
		  header('Location: /StudentHomePageAlbums.php');
		  
?>